# Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>

_realname=hayagriva
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.1
pkgrel=1
pkgdesc="Format references and citations for your YAML-encoded or BibLaTeX bibliography files and query bibliographies using selectors (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url="https://github.com/typst/hayagriva"
msys2_references=(
  'purl: pkg:cargo/hayagriva'
)
license=('spdx:Apache-2.0 OR MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
checkdepends=('git')
source=("https://github.com/typst/hayagriva/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "Cargo.lock")
sha256sums=('9b0fd5f1cca12da1f5885ed0510a1ee24a8ef5459fb6fb63cfc96fd3633d0091'
            'd809e9d8b83e1346c46c006c05d872d11b6a03b5972ece4de2f433e350c0a5f1')

prepare() {
  cd "${_realname}-${pkgver}"

  # lockfile is not generated upstream, regenerate it manually after update
  cp ../Cargo.lock .
  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"

  cargo build --release --frozen --all-features
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen --all-features
}

package() {
  cd "${_realname}-${pkgver}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}" \
    --all-features

  install -Dm644 LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  install -Dm755 target/release/${_realname} -t "${pkgdir}${MINGW_PREFIX}/bin"
}
